package com.inspur.ydt.util;


import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import com.inspur.ydt.service.TestService;

public class KeyInterceptor implements HandlerInterceptor {

	@Autowired
	TestService testService26;
	
	public void afterCompletion(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, Exception arg3)
			throws Exception {

	}

	
	public void postHandle(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, ModelAndView arg3)
			throws Exception {

	}

	
	public boolean preHandle(HttpServletRequest request,
			HttpServletResponse response, Object handler) throws Exception {
		System.out.println("执行preHandle方法-->01");
		
		String key = request.getParameter("key");
		String url = request.getRequestURI();
		
		System.out.println(key);
		System.out.println(url);
		boolean flag = testService26.getInfo(key, url);
		
		System.out.println(flag);
		if (flag) {
			System.out.println("验证成功，放行");
			return true;  //通过拦截器，继续执行请求
		} else {
			System.out.println("已拦截");
			request.setAttribute("msg", "拦截！！！");
//			request.getRequestDispatcher("Login.jsp").forward(request, response);
			response.sendRedirect(request.getContextPath() + "ydtapi/test/fail");
			return false;  //没有通过拦截器，返回登录页面
		}
	}
	

}
